package demo.practice.leetcode_msjd;

public class Msjd0109 {
    public static void main(String[] args) {
        Msjd0109 msjd0109 = new Msjd0109();
        msjd0109.isFlipedString("waterbosttle", "erbaottlewat");
    }

    public boolean isFlipedString(String s1, String s2) {
        if (s1 == null && s2 == null)
            return true;

        if (s1 == null || s2 == null)
            return false;

        int sum = 0;

        int[] arr = new int[100001];
        if (s1.length() != s2.length())
            return false;

        for (int i = 0; i < s1.length(); i++) {
            arr[s1.charAt(i)]++;
            sum++;
        }

        for (int i = 0; i < s2.length(); i++) {
            arr[s2.charAt(i)]--;
            sum--;
            if (arr[s2.charAt(i)] < 0)
                return false;
        }

        return sum == 0;
    }
}
